package com.zeedev.flyingsaucer.data;

import android.content.ContentValues;

import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;

public abstract class DatabaseConverter {
	
	private List<ContentValues> inputList = null;
	private List<ContentValues> beerList = null;
	private List<ContentValues> memberBeerList = null;
	
	public DatabaseConverter(List<ContentValues> inputList) {
		super();
		this.inputList = inputList;
		beerList = new ArrayList<ContentValues>(inputList.size());
		memberBeerList = new ArrayList<ContentValues>(inputList.size());
	}
	
	public enum Destination {
		BEERS,
		MEMBERBEER
	}
	
	protected abstract String mapColumn(String inputColumn, Destination destination);
	
	protected abstract ContentValues mapValues(String inputKey, Object currentValue, Destination destination);
	
	protected abstract Destination[] chooseLists(String inputColumn);

	public void seperateList() {
		for (int i = 0; i < getInputList().size(); i++) {
			ContentValues cv = getInputList().get(i);
			
			ContentValues beerCV = new ContentValues();
			ContentValues memberBeerCV = new ContentValues();
			
			for (Entry<String, Object> entry : cv.valueSet()) {

				
				String currentColumn = entry.getKey();
				Object currentValue = entry.getValue();
//				String currentValue = currentValueObject + "";
				
					
				
				
					Destination[] destinationLists = chooseLists(currentColumn);
					for (Destination curDestination : destinationLists) {
						if (curDestination == Destination.BEERS) {
							beerCV.putAll( mapValues(currentColumn, currentValue, curDestination) );
						}
						if ( curDestination == Destination.MEMBERBEER) {
							memberBeerCV.putAll( mapValues(currentColumn, currentValue, curDestination) );
						}
					}				
			}
			
			if (beerCV.size() > 0) {
				beerList.add(beerCV);
			}
			if (memberBeerCV.size() > 0) {
				memberBeerList.add(memberBeerCV);
			}
			
			
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public List<ContentValues> getInputList() {
		return inputList;
	}

	public void setInputList(List<ContentValues> inputList) {
		this.inputList = inputList;
	}

	public List<ContentValues> getBeerList() {
		return beerList;
	}

	public void setBeerList(List<ContentValues> beerList) {
		this.beerList = beerList;
	}

	public List<ContentValues> getMemberBeerList() {
		return memberBeerList;
	}

	public void setMemberBeerList(List<ContentValues> memberBeerList) {
		this.memberBeerList = memberBeerList;
	}
	
	
	
	

}
